import 'dart:async';
import 'package:flutter/material.dart';
import 'package:goumao_app/Customs/gm_app_util.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class GMLogoutUserPage extends StatefulWidget {
  static const String sName = "enter";

  const GMLogoutUserPage({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _CSLogoutUserPageState createState() => _CSLogoutUserPageState();
}

class _CSLogoutUserPageState extends State<GMLogoutUserPage> {
  /// 用户输入的密码
  String pwdData = '';
  late String payPwd;
  final picker = ImagePicker();
  var times = 5;
  // ignore: prefer_typing_uninitialized_variables
  var timer;

  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  void initState() {
    super.initState();
    timer = Timer.periodic(const Duration(seconds: 1), (time) {
      if (times == 0) {
        timer.cancel();
      } else {
        setState(() {
          times = times - 1;
        });
      }
      // 取消定时器
    });
  }

  @override
  void dispose() {
    timer?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
          centerTitle: true,
          elevation: 0.0,
          title: GMAppUtil.navText('账户注销')),
      body: _buildContent(context),
    );
  }

  Widget _buildContent(BuildContext c) {
    return Container(
      width: double.maxFinite,
      color: Colors.grey[100],
      child: Column(
        children: <Widget>[
          
          Container(
            alignment: Alignment.center,
            padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 20.w),
            child: Text(
              '帐号注销将清空用户全部信息',
              style: TextStyle(fontSize: 14.sp, color: Colors.grey),
            ),
          ),
          Container(
              margin: EdgeInsets.symmetric(horizontal: 4.w),
              color: Colors.grey[200],
              child: Column(children: [
                ListTile(
                  minLeadingWidth: 20.w,
                  leading: Text('·', style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w700)),
                  title:
                      const Text("注销后，帐号信息、会员权益等将被清空并无法恢复", style: TextStyle(fontWeight: FontWeight.bold)),
                ),
                ListTile(
                  minLeadingWidth: 20.w,
                  leading: Text('·', style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w700)),
                  title: const Text("基于安全政策考量，注销账号后90天内无法再次住册", style: TextStyle(fontWeight: FontWeight.bold)),
                ),
                ListTile(
                    minLeadingWidth: 20.w,
                    leading: Text('·', style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w700)),
                    title: const Text("以上信息，如有任何问题，请先咨询app客服，谨慎操作，如有问题，自行承担责任",
                        style: TextStyle(fontWeight: FontWeight.bold))),
                const Divider(),
                ListTile(
                    minLeadingWidth: 20.w,
                    leading: Text('', style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w700)),
                    title: const Text(
                      "注销账号的行为将视为您自愿放弃当前用户的所有权益，最终解释权归平台所有",
                      style: TextStyle(color: Colors.grey),
                    ))
              ])),
          Container(
              margin: EdgeInsets.symmetric(horizontal: 20.w, vertical: 20.h),
              width: double.maxFinite,
              height: 48,
              child: MaterialButton(
                color: GMAppUtil.kAppThemColor,
                disabledColor: Colors.grey,
                onPressed: times == 0 ? () => submit() : null,
                child: Text("确定注销${times == 0 ? "" : "($times)"}",
                    style: const TextStyle(color: Colors.white)),
              ))
        ],
      ),
    );
  }

  void submit() {
    
    // EasyLoadingUtil.showLoading();
    // HttpServices.modifyUserInfo(
    //     params: {"status": "1"},
    //     success: () {
    //       EasyLoadingUtil.hidden();
    //       ToastUtil.showMessage(message: '账号已注销！');
    //       Future.delayed(Duration(milliseconds: 500), () => logOut());
    //     },
    //     error: (error) {
    //       EasyLoadingUtil.hidden();
    //       ToastUtil.showMessage(message: error.message);
    //     });
  }

  logOut() {
    // WMSUser.getInstance().logOut();
    // Get.offAll(CSLoginPage(
    //   phone: '',
    // ));
  }
}